3 # Install software and create new empty database.
6 if ( ! ( is_readable( "./LocalSettings.php" )
7 && is_readable( "./AdminSettings.php" ) ) ) {
8 print "You must first create the files LocalSettings.php\n" .
9 "and AdminSettings.php based on the samples in the top\n" .
10 "source directory before running this install script.\n";
15 include_once( "./LocalSettings.php" );
16 include_once( "./AdminSettings.php" );
18 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
19 print "To use math functions, you must first compile texvc by\n" .
20 "running \"make\" in the math directory.\n";
28 # Make the necessary directories
30 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
31 foreach ( $dirs as $d ) { makedirectory( $d ); }
34 # Copy files into installation directories
36 print "Copying files...\n";
38 copyfile( ".", "LocalSettings.php", $IP );
39 copyfile( ".", "wiki.phtml", $IP );
40 copyfile( ".", "redirect.phtml", $IP );
41 copyfile( ".", "texvc.phtml", $IP );
43 $handle = opendir( "./includes" );
44 while ( false !== ( $f = readdir( $handle ) ) ) {
45 if ( "." == $f{0} ) continue;
46 copyfile( "./includes", $f, $IP );
49 $handle = opendir( "./stylesheets" );
50 while ( false !== ( $f = readdir( $handle ) ) ) {
51 if ( "." == $f{0} ) continue;
52 copyfile( "./stylesheets", $f, $wgStyleSheetDirectory );
55 copyfile( "./images", "wiki.png", $wgUploadDirectory );
56 copyfile( "./languages", "Language.php", $IP );
57 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
59 $fp = fopen( $wgDebugLogFile, "w" );
60 if ( false === $fp ) {
61 print "Could not create log file \"{$wgDebugLogFile}\".\n";
64 $d = date( "Y-m-d H:i:s" );
65 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
69 makedirectory( "{$IP}/math" );
70 makedirectory( $wgMathDirectory );
71 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
72 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
73 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
77 # Make and initialize database
79 print "\n* * *\nWarning! This script will completely erase the\n" .
80 "existing database \"{$wgDBname}\" and all its contents.\n" .
81 "Are you sure you want to do this? (yes/no) ";
83 $response = readconsole();
84 if ( ! ( "Y" == $response{0} ||
"y" == $response{0} ) ) { exit(); }
86 print "\nYou should have already created a root password for the database.\n" .
87 "Enter the root password here: ";
89 $rootpw = readconsole();
91 $rconn = mysql_connect( $wgDBserver, "root", $rootpw );
92 if ( false === $rconn ) {
93 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
97 # Include rest of code to get things like internationalized messages.
99 include_once( "{$IP}/Setup.php" );
100 $wgTitle = Title
::newFromText( "Installation script" );
102 # Now do the actual database creation
104 print "Creating database...\n";
105 dbsource( $rconn, "./maintenance/database.sql" );
107 mysql_select_db( $wgDBname, $rconn );
108 dbsource( $rconn, "./maintenance/tables.sql" );
109 dbsource( $rconn, "./maintenance/users.sql" );
110 dbsource( $rconn, "./maintenance/initialdata.sql" );
112 populatedata(); # Needs internationalized messages
114 print "Adding indexes...\n";
115 dbsource( $rconn, "./maintenance/indexes.sql" );
117 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test,\n" .
118 "or \"run WikiSuite -b -o\" in test suite.\n";
122 # Functions used above:
124 function makedirectory( $d ) {
125 global $installOwner, $installGroup;
127 if ( is_dir( $d ) ) {
128 print "Directory \"{$d}\" exists.\n";
130 if ( mkdir( $d, 0777 ) ) {
131 if ( isset( $installOwner ) ) { chown( $d, $installOwner ); }
132 if ( isset( $installGroup ) ) { chgrp( $d, $installGroup ); }
133 print "Directory \"{$d}\" created.\n";
135 print "Could not create directory \"{$d}\".\n";
141 function copyfile( $sdir, $name, $ddir, $perms = 0644 ) {
142 global $installOwner, $installGroup;
144 $d = "{$ddir}/{$name}";
145 if ( copy( "{$sdir}/{$name}", $d ) ) {
146 if ( isset( $installOwner ) ) { chown( $d, $installOwner ); }
147 if ( isset( $installGroup ) ) { chgrp( $d, $installGroup ); }
149 # print "Copied \"{$name}\" to \"{$ddir}\".\n";
151 print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
156 function readconsole() {
157 $fp = fopen( "php://stdin", "r" );
158 $resp = trim( fgets( $fp ) );
164 # Read and execute SQL commands from a file
166 function dbsource( $conn, $fname ) {
167 $fp = fopen( $fname, "r" );
168 if ( false === $fp ) {
169 print "Could not open \"{$fname}\".\n";
176 while ( ! feof( $fp ) ) {
177 $line = trim( fgets( $fp ) );
178 $sl = strlen( $line ) - 1;
180 if ( $sl < 0 ) { continue; }
181 if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
183 if ( ";" == $line{$sl} ) {
185 $line = substr( $line, 0, $sl );
188 if ( "" != $cmd ) { $cmd .= " "; }
192 $cmd = replacevars( $cmd );
193 $res = mysql_query( $cmd, $conn );
195 if ( false === $res ) {
196 print "Query \"{$cmd}\" failed.\n";
207 function replacevars( $ins ) {
209 "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
210 "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
211 "wgDBadminuser", "wgDBadminpassword"
214 foreach ( $varnames as $var ) {
216 $ins = str_replace( '{$' . $var . '}', $
$var, $ins );
221 function populatedata() {
222 global $wgDBadminpassword;
223 $fname = "Installation script: populatedata()";
225 $sql = "DELETE FROM site_stats";
226 wfQuery( $sql, $fname );
228 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
229 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
230 wfQuery( $sql, $fname );
232 $sql = "DELETE FROM user";
233 wfQuery( $sql, $fname );
235 $sql = "INSERT INTO user (user_name, user_password, user_rights)" .
236 "VALUES ('WikiSysop','" . User
::encryptPassword( $wgDBadminpassword ) .
237 "','sysop'),('WikiDeveloper','" . User
::encryptPassword(
238 $wgDBadminpassword ) . "','sysop,developer')";
239 wfQuery( $sql, $fname );
241 $wns = Namespace::getWikipedia();
242 $ulp = addslashes( wfMsg( "uploadlogpage" ) );
243 $dlp = addslashes( wfMsg( "dellogpage" ) );
245 $sql = "DELETE FROM cur";
246 wfQuery( $sql, $fname );
248 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
249 "cur_restrictions) VALUES ({$wns},'{$ulp}','" .
250 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop')";
253 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
254 "cur_restrictions) VALUES ({$wns},'{$dlp}','" .
255 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop')";